const tree = {
    name: 'root',
    children: [
        { name: '叶子1-1' },
        { name: '叶子1-2' },
        {
            name: '叶子2-1',
            children: [{
                name: '叶子3-1',
                children: [{
                    name: '叶子4-1',
                    children: [{}]
                }]
            }]
        }
    ]
}

let count = 0
let maxCount = 0
function depthOfTree(tree) {
    count++
    if (count > maxCount) maxCount = count
    const {name,children} = tree
    if (!children) return
    if (children) {
        children.forEach(item => {
            depthOfTree(item)
            count--
        })
    }
    return maxCount
}

console.log(depthOfTree(tree))
